package com.wl.cloud.core.utils;

import com.fasterxml.jackson.databind.JavaType;
import com.wl.cloud.core.mapper.JsonMapper;

import java.util.Collection;
import java.util.Map;

/**
 * @author: wanglin
 * @date: 2023-04-13 周四
 * @Version: 1.0
 * @Description:
 */
public class JsonMapperUtil {
    private static final JsonMapper instance = new JsonMapper();

    private JsonMapperUtil() {
    }

    public static String toJson(Object object) {
        return instance.toJson(object);
    }

    public static <T> T fromJson(String jsonString, Class<T> cls) {
        return instance.fromJson(jsonString, cls);
    }

    public static <T> T fromJson(String jsonString, JavaType javaType) {
        return instance.fromJson(jsonString, javaType);
    }

    public static JavaType constructCollectionType(Class<? extends Collection> collectionClass, Class<?> elementClass) {
        return instance.constructCollectionType(collectionClass, elementClass);
    }

    public static JavaType constructMapType(Class<? extends Map> mapClass, Class<?> keyClass, Class<?> valueClass) {
        return instance.constructMapType(mapClass, keyClass, valueClass);
    }
}
